/**
 * Copyright (C)  Gadglet .
 *
 * This file is part of Gadglet
 *
 * Gadglet is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gadglet is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Gadglet. If not, see <http://www.gnu.org/licenses/>.
 */

package com.gadglet.client.gwt;


/**
 * GWT client class includes native (javascript) apis. Always use in try,catch
 * 
 */
public class GadgetNativeUtils {

	/**
	 * set dynamically the Gadget title must enable <Require
	 * feature="settitle"/>
	 * 
	 * @param title
	 */
	public static native void setTitle(String title) /*-{
		$wnd.gadgets.window.setTitle(title);
	}-*/;

	/**
	 * @return the gadget width in pix
	 */
	public static native int getGadgetWidth() /*-{
		return $wnd.gadgets.window.getViewportDimensions().width;
	}-*/;

	/**
	 * @return gadget Height
	 */
	public static native int getGadgetHeight() /*-{
		return $wnd.gadgets.window.getViewportDimensions().height;
	}-*/;

	/**
	 * @return current user language
	 */
	public static native String getLang() /*-{
		var prefs = new gadgets.Prefs();
		return prefs.getLang();

	}-*/;

	/**
	 * @return the Gadget current view: "home", "canvas", "profile" ... must
	 *         declare <Require feature="views"/>
	 */
	public static native String getCurrentView() /*-{
		return $wnd.gadgets.views.getCurrentView().getName();

	}-*/;

	/**
	 * navigate the Gadget to the canvas view
	 * 
	 * @param params
	 *            extra params.
	 *            
	 */
	public static native void requestNavigateToCanvas(String params) /*-{
		
		var paramsObject = eval(params);
		
		$wnd.gadgets.views.requestNavigateTo('canvas', paramsObject);
	}-*/;
	
	
	/**
	 * navigate the Gadget to the canvas view
	 * 
	 */
	public static native void requestNavigateToCanvas() /*-{
		$wnd.gadgets.views.requestNavigateTo('canvas', null);
	}-*/;
	
	
	/**
	 * @return - parameters sent when navigation request was done
	 */
	public static native String getNavigateToCanvasParam(String name) /*-{
		
		var navParams = $wnd.gadgets.views.getParams();
		
		return navParams[name];
	}-*/;
	

	/**
	 * change the height of the gadget must declare <Require
	 * feature="dynamic-height"/>
	 * 
	 * @param height
	 */
	public static native void adjustHeight(int height) /*-{
		$wnd.gadgets.window.adjustHeight(height);
	}-*/;

	public static native void requestShareApp(String id, String message) /*-{
		$wnd.opensocial
				.requestShareApp(id, $wnd.opensocial.newMessage(message));
	}-*/;

}
